"""
AdminLoginPage商品管理页面
author : 吕俊
2022.01.06
"""
from Common.Base import Base, open_browser

login_url = "http://localhost:8080/ecshop/admin/"


class AdminLoginPage(Base):
    login_page_doc = ('css selector', '.panel-cross>span')
    login_ec_doc = ('id', 'cloudLogin')
    login_username_doc = ('name', 'username')
    login_password_doc = ('name', 'password')
    login_button_doc = ('css selector', '.last>input')


    def go_url(self, url: str):
        """
        进入后台admin网页
        :return:
        """
        self.open_url(url)
        self.click(self.login_page_doc)
        self.click(self.login_ec_doc)
        self.send_keys(self.login_username_doc, 'root')
        self.send_keys(self.login_password_doc, 'root123456')
        self.click(self.login_button_doc)

    def is_login_success(self, username):
        self.driver.switch_to.frame('menu-frame')
        self.login_ec_loc = ('css selector', '#foot-div>a')
        """
        判断是否登录成功,如果成功,返回True,反之返回False
        :return:
        """
        return self.is_text_equal_in_element(self.login_ec_loc, username)


if __name__ == '__main__':
    go_goods = AdminLoginPage(open_browser())
    go_goods.go_url(login_url)
    go_goods.is_login_success('root')
    go_goods.close_browser()
